namespace array_demo.Model.Queue
{
    public class ArrayQueue<E> : IQueue<E>
    {
        private Array1<E> array;

        public ArrayQueue(int capacity)
        {
            array = new Array1<E>(capacity);
        }

        public ArrayQueue()
        {
            array = new Array1<E>();
        }

        public int Count => array.Count;

        public bool IsEmpty => array.IsEmpty();

        /// <summary>
        /// 队列的头部读取和删除一个元素 出队
        /// </summary>
        /// <returns></returns>
        public E Dequeue()
        {
            return array.DeleteFirst();
        }

        /// <summary>
        /// 在队列的末端添加元素 入队
        /// </summary>
        /// <param name="e"></param>
        public void Enqueue(E e)
        {
            array.AddLast(e);
        }

        /// <summary>
        /// 在队列的头读取一个元素，但是不删除它
        /// </summary>
        /// <returns></returns>
        public E Peek()
        {
            return array.GetFirst();
        }

        public override string ToString()
        {
            return "queue" + array.ToString() + "top";
        }
    }
}